﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ping
{
    public class Send
    {
        public string Hostname { get; private set; }
        public long RoundtripTime { get; private set; }
        public int Ttl { get; private set; }
        public System.Net.NetworkInformation.IPStatus Status { get; private set; }

        public Send(string hostname, bool DontFragment, int PacketSize, int timeout)
        {
            Hostname = hostname;
            var options = new System.Net.NetworkInformation.PingOptions();
            options.DontFragment = DontFragment;

            var data = new string('a', PacketSize);
            var buffer = Encoding.ASCII.GetBytes(data);
            var sender = new System.Net.NetworkInformation.Ping();

            var reply = sender.Send(hostname, timeout, buffer, options);
            Status = reply.Status;
            RoundtripTime = reply.RoundtripTime;
            Ttl = (Status == System.Net.NetworkInformation.IPStatus.Success &&
                reply.Options != null) ? reply.Options.Ttl : 0;
        }
    }
}
